package com.shroo8.footballbloglib.dao.footballblogwrite;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.jdbc.core.SqlParameter;
import org.springframework.stereotype.Repository;

import com.shroo8.footballbloglib.dao.constants.DataAccessConstants;
import com.shroo8.footballbloglib.dao.util.DaoUtil;

@Repository(value="updateArticleDao")
public class UpdateArticleDao {
	@Resource(name="dataSourceFootballblogWrite")
	protected DataSource dataSource;
	
	protected final String sql = DataAccessConstants.SP_UPDATE_ARTICLE;
	
	@Resource(name="daoUtil")
	protected DaoUtil daoUtil;

	/*
	 * 	Parameter list:
	(
		in_article_id VARCHAR(36),
		in_article_title VARCHAR (100),
		in_article_text VARCHAR (10000)
	)
	*/
	public void execute(String articleId, String articleTitle, String articleText){
		List<SqlParameter> sqlParameters = new ArrayList<SqlParameter>();
	    Map<String, Object> inParams = new HashMap<String, Object>();
	    
	    sqlParameters.add(new SqlParameter(DataAccessConstants.ARTICLES_ARTICLE_ID, Types.VARCHAR));
        inParams.put(DataAccessConstants.ARTICLES_ARTICLE_ID, articleId);

	    sqlParameters.add(new SqlParameter(DataAccessConstants.ARTICLES_ARTICLE_TITLE, Types.VARCHAR));
        inParams.put(DataAccessConstants.ARTICLES_ARTICLE_TITLE, articleTitle);

	    sqlParameters.add(new SqlParameter(DataAccessConstants.ARTICLES_ARTICLE_TEXT, Types.VARCHAR));
        inParams.put(DataAccessConstants.ARTICLES_ARTICLE_TEXT, articleText);

        daoUtil.spExecute(dataSource, sql,
                sqlParameters, inParams);
	}

}
